package com.rongke.web;

import com.rongke.commons.JsonResp;
import com.rongke.mapper.PropNameMapper;
import com.rongke.model.PropName;
import com.rongke.service.PropNameService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;

/**
 * @PropNameController
 * @属性名Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/propName")
@Transactional
@CrossOrigin
public class PropNameController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private PropNameService propNameService;

    /**
     * @添加属性名
     * @param propName
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addPropName(@RequestBody PropName propName){
        log.debug("添加属性名");
        propName.setGmtDatetime(new Date());
        propNameService.insert(propName);
        return JsonResp.ok(propName);
    }

    /**
     * @修改属性名
     * @param propName
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updatePropName(@RequestBody PropName propName){
        log.debug("修改属性名");
        propName.setUptDatetime(new Date());
        propNameService.updateById(propName);
        return JsonResp.ok(propName);
    }
    /**
     * @根据id查找属性名
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectPropName(Long id){
        log.debug("查找属性名");
        PropName propName = propNameService.selectById(id);
        return JsonResp.ok(propName);
    }

    /**
     * @根据条件查找属性名
     * @param propName
     * @return 返回值JsonResp
     */
    @RequestMapping(value = "/selectByCondition", method = RequestMethod.POST)
    public JsonResp selectPropNameByCondition(@RequestBody PropName propName){
        log.debug("根据条件查找属性名");
        if(propName==null)
            return JsonResp.toFail("参数不能为空");
        List<PropName> propNameList=propNameService.selectByCondition(propName);
        return JsonResp.ok(propNameList);
    }

}
